package com.ruoyi.web.controller.xcx;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.annotation.ResultFilter;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.AData;
import com.ruoyi.system.domain.ADataInfo;
import com.ruoyi.system.domain.dto.ADataInfoDTO;
import com.ruoyi.system.domain.vo.XcxADataInfoVO;
import com.ruoyi.system.service.IADataInfoService;
import com.ruoyi.system.service.IADataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 素材库详情Controller
 *
 * @author ruoyi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/xcx/aDataInfo")
public class XcxADataInfo extends BaseController {

    @Autowired
    private IADataInfoService aDataInfoService;
    @Resource
    private IADataService aDataService;

    /**
     * 查询素材库详情列表
     */
    @GetMapping("/list")
    @ResultFilter
    public TableDataInfo list(ADataInfoDTO aDataInfo) {
        Long dataId = aDataInfo.getDataId();
        if(ObjectUtil.isNotNull(dataId)){
            AData aData = new AData();
            aData.setAncestors(String.valueOf(dataId));
            List<AData> dataList = aDataService.selectADataList(aData);
            List<Long> dataIdList = dataList.stream().map(AData::getId).collect(Collectors.toList());
            dataIdList.add(0, dataId);
            aDataInfo.setDataIdList(dataIdList);
            aDataInfo.setDataId(null);
        }

        startPage();
        List<ADataInfo> list = aDataInfoService.selectADataInfoXcxList(aDataInfo);
        return getDataTable(list);
    }

    /**
     * 获取素材库详情详细信息
     */
    @GetMapping(value = "/getXcxInfo")
    @ResultFilter
    public AjaxResult getXcxInfo(XcxADataInfoVO xcxADataInfo)
    {
        return success(aDataInfoService.selectADataInfoByInfo(xcxADataInfo));
    }
}
